<?php
/*
 * @Author: 哲学家乔布斯 <wuyangii@qq.com>
 * @Date: 2022-10-20 21:41:37
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-11-07 22:37:15
 * @Descripttion: 用户信息
 */
namespace app\agent\controller\system;
use think\Db;
class User extends \app\agent\controller\Common
{
    public function index(){
    
        return view();
    }

    public function list(){
        $limit = request()->param('limit') ?? 15;
        $page = request()->param('page');
        $page = $page ? ($page - 1) * $limit : 0;
        $search = request()->param();
        $query = (new \app\common\model\User())->where(['agent_id' => $this->userInfo['id']]);
        isset($search['goods_title']) && $search['goods_title'] != "" ? $query->where("title like '%{$search['goods_title']}%'") : '';
        isset($search['id']) && $search['id'] != "" ? $query->where("id = '{$search['id']}'") : '';
        $query->order("id desc");

        $list = $query->limit($page, $limit)->append([])->select();
        $count = $query->count();
        return self::successResult('',$list,$count);
    }
    public function edit(){
        if (request()->isPost()) {
            $data = request()->param('info');
            $id = request()->param('id');

            $table = new \app\common\model\User();
            $row = $table->allowField(true)->save($data, ['id' => $id]);
            if ($row) {
                return self::successResult();
            } else {
                return self::errorResult();
            }
        } else {
            $id = intval(request()->param('id'));
            $info = (new \app\common\model\User())->append(['bus_title','driver_title'])->where(['id' => $id])->find();
            $this->assign('info',$info);
            return view();
        }
    }

   
}
